# 注册  登录 程序

# 注册 保存  在' D:' md5 文件 中
# 文件的内容为 {'用户名1的MD5值':'用户名1密码的MD5值','用户名2的MD5值'：'2密码的MD5值'}

# 登录时读取密码文件中的内容，判断是否登陆成功

# 最后将 D盘文件 copy 到 E盘进行备份

import hashlib
import json

def regiest(username,password):
    dict1 = {}
    username_md5 = record_md5(username)
    password_md5 = record_md5(password)
    dict1[username_md5] = username_md5
    dict1[password_md5] = password_md5
    json_md5 = json.dumps(dict1)
    recordfile(json_md5)



def recordfile(json_str):


    with open('密码.txt','w+',encoding='utf8') as file:
        file.write(json_str)

def record_md5(str,encode_type='utf8'):
    md5 = hashlib.md5()
    md5.update(str.encode(encode_type))
    str_md5 = md5.hexdigest()
    return str_md5

def loading(username,password):
    dict2 = {}
    username_md5 = record_md5(username)
    password_md5 = record_md5(password)
    dict2[username_md5] = username_md5
    dict2[password_md5] = password_md5
    # json_loading = json.dumps(dict2)
    with open ('密码.txt','r',encoding='utf8') as readfile:
        read_file = readfile.read()
        load_json = json.loads(read_file)
    if username_md5 in load_json and :
        print('登陆成功！')
    else:
        print('登陆失败！')



# regiest('Dancy陈','222677')
# loading('Dancy','222677')
def main():
    print('请先注册')
    regiest_username = input('输入注册用户名')
    regiest_password = input('输入注册密码：')
    regiest(regiest_username,regiest_password)









